<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="接口名称">
              <a-input placeholder="请输入接口名称" v-model="queryParam.projectName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button @click="projectAssignModal" type="primary" icon="plus" style="margin-left: 8px"
                >分配接口</a-button
              >
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!--   <a-button @click="handleAdd" type="primary" icon="plus" style="margin-left: 8px">新增</a-button> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>

    <dp-t-scope-api-modal ref="modalForm" @ok="modalFormOk"></dp-t-scope-api-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import DpTScopeApiModal from './modules/DpTScopeApiModal'
import { api } from './DpTScopeDataService.js'
import { postAction, deleteAction } from '@/api/manage'

export default {
  name: 'DpTScopeDataList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    DpTScopeApiModal
  },
  data() {
    return {
      disableMixinCreated: true,
      description: 'dp_t_scope_data管理页面',
      // 表头
      columns: [
        {
          title: '接口名称',
          align: 'center',
          dataIndex: 'name'
        },
        {
          title: '请求路径',
          align: 'center',
          dataIndex: 'path'
        },
        {
          title: '所属子系统',
          align: 'center',
          dataIndex: 'systemName'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/datapipeline/biz/dpTScopeDatas/api/',
        delete: '/datapipeline/biz/dpTScopeDatas/api/',
        deleteBatch: api.deleteBatch,
        exportXlsUrl: api.exportXlsUrl,
        importExcelUrl: api.importExcelUrl
      },
      dictOptions: {},
      queryParam: {}
    }
  },
  created() {
    this.queryParam.appKey = this.$route.params.appKey
    this.loadData()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}${this.url.importExcelUrl}`
    }
  },
  methods: {
    projectAssignModal() {
      this.$refs.modalForm.add(this.queryParam)
      this.$refs.modalForm.title = '分配接口'
      this.$refs.modalForm.disableSubmit = false
    },
    initDictConfig() {},
    handleDelete: function(id) {
      if (!this.url.delete) {
        this.$message.error('请设置url.delete属性!')
        return
      }
      debugger
      var that = this
      deleteAction(that.url.delete + this.queryParam.appKey + '/' + id).then(res => {
        if (res.success) {
          //重新计算分页问题
          that.reCalculatePage(1)
          that.$message.success(res.message)
          that.loadData()
        } else {
          that.$message.warning(res.message)
        }
      })
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>

